package com.wl2o2o.basic;

import java.util.Scanner;


public class HexToOctal {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer num = scanner.nextInt();

        String[] nums = new String[num];
        Integer[] decimal = new Integer[num];
        String[] octal = new String[num];

        for(int i = 0 ; i < num ; i++) {
            nums[i] = scanner.next();
        }
        //16转换为十进制
        for(int j = 0 ; j < num ; j++) {
            //将转换过的十进制数字放入decimal数组
            decimal[j] = Integer.parseInt(nums[j], 16);
            //decimal数组中的每一个数转换到八进制数组
            octal[j] = Integer.toOctalString(decimal[j]);
        }
        //十进制转8进制
        for (String string : octal) {
            System.out.println(string);
        }
        scanner.close();
    }
}
